/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.iasd.youthshelter.honor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.TopComponent;

@ActionID(
        category = "File/New",
        id = "pt.iasd.youthshelter.honor.NewHonorEditorAction"
)
@ActionRegistration(
        displayName = "#CTL_NewHonorEditorAction"
)
@ActionReference(path = "Menu/File/New"/*, position = 1300*/)
@Messages("CTL_NewHonorEditorAction=Honor")
public final class NewHonorEditorAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        NotifyDescriptor.InputLine input = new NotifyDescriptor.InputLine(
            NbBundle.getMessage(NewHonorEditorAction.class, "Input.Honor.Name"),
            NbBundle.getMessage(NewHonorEditorAction.class, "Input.Honor.Title")
        );
        if(DialogDisplayer.getDefault().notify(input) == NotifyDescriptor.OK_OPTION
                && input.getInputText() != null && !input.getInputText().isEmpty()) {
            TopComponent editor = new HonorEditorTopComponent(input.getInputText());
            editor.open();
            editor.requestActive();
        }
    }
}
